package com.shaoyu.tools.mp.generate;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @Desc :
 * @Author: shaoyu
 * @Date : 2022/8/22 11:23
 */
public class Main {
//    private static String url = "jdbc:mysql://10.4.144.58:3307/bomber?rewriteBatchedStatements=true&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false";
//    private static String username = "root";
//    private static String password = "123456";

    //show-master
//    private static String url = "jdbc:mysql://wh.showtestdb.w.qiyi.db:1527/show_test?rewriteBatchedStatements=true&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false";
//    private static String username = "show_test";
//    private static String password = "VViFD0V0";
    //show-live
//    private static String url = "jdbc:mysql://sh.dbtest2.w.qiyi.db:8832/live_test?rewriteBatchedStatements=true&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false";
//    private static String username = "live";
//    private static String password = "k2c3DDc_";

    //show-analyze
    private static String url = "jdbc:mysql://sh.dbtest3.w.qiyi.db:8663/analyze_test?rewriteBatchedStatements=true&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false";
    private static String username = "show_ugc_test";
    private static String password = "ShdwiPed";


    private static DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig.Builder(url,username,password);

    private static String author = "shaoyu";

    //桌面
    private static String outputDir = "/Users/swicky/data/mybatisplus/";
    private static String parentPackageName = "com.shaoyu.generate";
    private static String moduleName = "demo";

    //为空表示所有
    private static final String[] tables = {"chat_anchor_base_statistical_info_daily"};

    public static void main(String[] args) {
        FastAutoGenerator.create(DATA_SOURCE_CONFIG)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir(outputDir); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent(parentPackageName) // 设置父包名
                            .moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, outputDir)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables) // 设置需要生成的表名
                            //Controller配置
                            .controllerBuilder()
                            .enableFileOverride()
                            .enableRestStyle() //开启生成@RestController 控制器
                            .enableHyphenStyle() //开启驼峰转连字符
                            .build()
                            //entity配置
                            .entityBuilder()
                            .enableLombok()
                            .enableFileOverride()
                            .idType(IdType.AUTO)
                            .build()
                            //Mapper配置
                            .mapperBuilder()
                            .enableBaseColumnList()
                            .enableFileOverride()
                            .enableBaseResultMap()
                            .build();
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
